import React from "react";
import {Input, InputNumber, Select} from 'antd';
import PropTypes from 'prop-types';
import {omit} from "lodash-es";
import BaseInputField from "../Base/BaseInputField";
import {sleepFunc} from "jh-utils";

export default class InputBase extends BaseInputField {

    static propTypes = {
        ...BaseInputField.propTypes
    };

    moreCommonProps() {
        return [
            ...super.moreCommonProps(),
            'password', 'textarea', 'defaultOpen'
        ]
    }

    hdlValueChange(value) {
        let val = value;
        if (value && value.target) {
            val = value.target.value;
        }
        super.hdlValueChange(val);
    }

    mainRender(context) {
        const {password, textarea} = this.props;
        const cProps = omit(this.props, this.commonProps);
        cProps.allowClear = true;
        cProps.value = this.state.value;
        cProps.onChange = this.hdlValueChange.bind(this);
        cProps.onBlur = this.hdlValueBlur.bind(this);
        cProps.onFocus = this.hdlValueFocus.bind(this);

        const Comp = password ? Input.Password : (
            textarea ? Input.TextArea : Input
        );

        return <Comp
            {...cProps}
            ref={this.refFunc.bind(this)}
        />;
    }
}
